package com.xxlie.shop.repository;

import com.xxlie.auth.domain.User;
import com.xxlie.core.common.StatusConstant;
import com.xxlie.shop.domain.Feedback;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Date;
import java.util.List;
import java.util.Optional;

public interface FeedbackRepository extends JpaRepository<Feedback, Long>, JpaSpecificationExecutor<Feedback> {
    @Query("select a from Feedback a where a.id=:id and delFlag = '" + StatusConstant.DEL_FLAG_NORMAL + "'")
    Optional<Feedback> findOne(@Param("id") int id);

    @Modifying
    @Query("update Feedback set delFlag='" + StatusConstant.DEL_FLAG_DELETE + "' where id = ?1")
    void deleteById(Long id);

    Feedback save(Feedback feedback);

    List findAllByUserAndCreateDateGreaterThanEqual(User user, Date createStartDate);
}
